/*     */ package com.chw.admin.user;
/*     */ 
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;

/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Service;

import com.chw.utils.Md5EncryptUtil;
import com.chw.utils.UUIDUtil;
import com.github.pagehelper.PageHelper;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ 
/*     */ @Service
/*     */ public class SysUserService
/*     */   implements ISysUserService
/*     */ {
/*     */ 
/*     */   @Autowired
/*     */   private SysUserMapper sysUserMapper;
/*     */ 
/*     */   public SysUser selectById(String id)
/*     */     throws Exception
/*     */   {
/*  33 */     return this.sysUserMapper.selectById(id);
/*     */   }
/*     */ 
/*     */   public SysUser selectByAccount(String account)
/*     */   {
/*  38 */     if ((account != null) && (!"".equals(account))) {
/*  39 */       return this.sysUserMapper.selectByAccount(account);
/*     */     }
/*  41 */     return null;
/*     */   }
/*     */ 
/*     */   public PageInfo<SysUser> page(SysUser record, int currentPage, int pageSize)
/*     */     throws Exception
/*     */   {
/*  53 */     PageHelper.startPage(currentPage, pageSize);
/*  54 */     List list = this.sysUserMapper.find(record);
/*  55 */     return new PageInfo(list);
/*     */   }
/*     */ 
/*     */   public void saveOrUpdate(SysUser record)
/*     */     throws Exception
/*     */   {	
				record.setCreatedBy(UUIDUtil.getUUID());
				record.setId(UUIDUtil.getUUID());
				record.setEnabledFlag("Y");
				record.setCreatedDate(new Date());
				record.setLastUpdatedBy(UUIDUtil.getUUID());
				record.setLastUpdatedDate(new Date());
				record.setStatus("Y");
				record.setPassword(Md5EncryptUtil.encode(record.getPassword(),true));
				this.sysUserMapper.insert(record);
/*     */   }
/*     */ 
/*     */   public void updateStatus(String id, String status)
/*     */     throws Exception
/*     */   {
/* 150 */     Map map = new HashMap();
/* 151 */     map.put("id", id);
/* 152 */     map.put("status", status);
/* 153 */     this.sysUserMapper.updateSelective(map);
/*     */   }
/*     */ 
/*     */   public void resetException(String id)
/*     */     throws Exception
/*     */   {
/* 159 */     Map map = new HashMap();
/* 160 */     map.put("id", id);
/* 161 */     map.put("errorCount", Integer.valueOf(0));
/* 162 */     this.sysUserMapper.updateSelective(map);
/*     */   }
/*     */ 
/*     */   public void delete(String id) throws Exception
/*     */   {
/* 167 */     Map map = new HashMap();
/* 168 */     map.put("id", id);
/* 168 */     map.put("enabledFlag", "N");
/*     */ 
/* 170 */     this.sysUserMapper.updateSelective(map);
/*     */   }
/*     */ 
/*     */   public boolean hasAccount(String name, String id)
/*     */     throws Exception
/*     */   {
/* 176 */     SysUser user = new SysUser();
/* 177 */     user.setAccount(name);
/* 178 */     List list = this.sysUserMapper.find(user);
/* 179 */     if ((list != null) && (list.size() == 1))
/*     */     {
/* 181 */       if (StringUtils.isNotBlank(id))
/*     */       {
/* 183 */         user = (SysUser)list.get(0);
/* 184 */         if (id.equals(user.getId())) {
/* 185 */           return false;
/*     */         }
/*     */       }
/* 188 */       return true;
/*     */     }
/* 190 */     return false;
/*     */   }
/*     */ 
/*     */   private void sendMessageToQueue(String data, String operate) {
/* 194 */     Map message = new HashMap();
/* 195 */     message.put("data", data);
/* 196 */     message.put("operate", operate);
/*     */   }
/*     */ 
/*     */   public boolean hasNameAndAccount(SysUser record)
/*     */   {
/* 202 */     boolean bool = false;
/* 203 */     int i = this.sysUserMapper.hasNameAndAccount(record);
/* 204 */     if (0 < i) {
/* 205 */       bool = true;
/*     */     }
/* 207 */     return bool;
/*     */   }
/*     */ 
/*     */   public boolean pwdOld(String pwdOld, String id) throws Exception
/*     */   {
/* 212 */     boolean bool = false;
/* 213 */     SysUser user = this.sysUserMapper.selectById(id);
/* 214 */     if (StringUtils.isNotBlank(user.getPassword()));
/* 221 */     return bool;
/*     */   }
/*     */ 
/*     */   public boolean isRole()
/*     */   {
/* 226 */     boolean bool = false;
/* 227 */     Map map = new HashMap();
/*     */ 
/* 229 */     map.put("roleName", "平台运营方");
/* 230 */     int i = this.sysUserMapper.isRoleOfAdmin(map);
/*     */ 
/* 234 */     return bool;
/*     */   }
/*     */ }

